package com.hitrust.gs.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.hitrust.gs.bean.GSProductTypeManagerBean;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;

public class GSProductTypeManagerDao extends GSBaseDAO{

	public GSProductTypeManagerBean findByTypeCode(String typeCode) throws GSException{        
	        String tSql = "select * from t_product_type_manager" +
	                "  where  product_type = ? and status = '1' ";
	        ArrayList tList = null;
	        GSProductTypeManagerBean bean = null;
	        Object[] tObj = {typeCode};
	        try{
	            tList = this.executeQuery(new GSProductTypeManagerBean(),tSql,tObj);
	            if(tList.size() > 0)
	            	bean = (GSProductTypeManagerBean)tList.get(0);
	        }catch(Exception e){
	            GSLogWriter.error(this,e.toString());
	            throw new GSException(GSException.E19999,GSException.E19999_MSG);
	        }
	        
	        return bean;
	}
	
	/**
	 * 根据ID查询产品分类表
	 * @param Id
	 * @return
	 * @throws GSException
	 */
	public boolean findProductTypeManagerById (String Id) throws GSException{
		String tSql = " select * from t_product_type_manager where id = ?";
		boolean tFlag = false;
		Object[] object = {Id};
		try {
			ArrayList tList = this.executeQuery(new GSProductTypeManagerBean(), tSql, object);
			if(tList.size()>0){
				tFlag = true;
			}
		} catch (Exception e) {
			 throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		return tFlag;
	}
	
	
	public GSProductTypeManagerBean findByTypeCodeAndPUpperCode(String typeCode,String upperCode) throws GSException{    
		if("".equals(typeCode.trim())){
			return null;
		}
        String tSql = "select * from t_product_type_manager" +
                "  where  product_type = ? and status = '1' and upper_type = ? ";
        ArrayList tList = null;
        GSProductTypeManagerBean bean = null;
        Object[] tObj = {typeCode,upperCode};
        try{
            tList = this.executeQuery(new GSProductTypeManagerBean(),tSql,tObj);
            if(tList.size() > 0)
            	bean = (GSProductTypeManagerBean)tList.get(0);
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        
        return bean;
}
	public Map findAllByTypeCodeAndPUpperCode(String upperCode) throws GSException{    
        String tSql = "select * from t_product_type_manager" +
                "  where  status = '1' and upper_type = ? ";
        ArrayList tList = null;
        Map map= new HashMap();
        GSProductTypeManagerBean bean = null;
        Object[] tObj = {upperCode};
        try{
            tList = this.executeQuery(new GSProductTypeManagerBean(),tSql,tObj);
            if(tList!=null&&tList.size() > 0){
            	for(int i=0;i<tList.size();i++){
            		bean = (GSProductTypeManagerBean)tList.get(i);
            		map.put(""+bean.getProduct_type(),bean.getType_name());
            	}
            }
            	
            
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        
        return map;
}
}
